package tech.realcpf.duckengine1.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.ResultSet;

public final class ResultUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(ResultUtil.class);
    public static void print(ResultSet rs) {
        try {
            int count = rs.getMetaData().getColumnCount();
            for (int i=1;i<=count;i++){
                System.out.printf("%s\t",rs.getMetaData().getColumnName(i));
            }
            System.out.println("\t".repeat(count));
            while (rs.next()) {
                for (int i=1;i<=count;i++){
                    System.out.printf("%s\t",rs.getString(i));
                }
                System.out.println();
            }
            rs.close();
        }catch (Exception e) {
            LOGGER.error("error when print result",e);
        }
    }
}
